__doc__ = """
Bootstraps and installs cmake into default buildext install folder for the Linux platform.
Windows todo, currently buildext users should install cmake to use the CMakeBuilder
"""

def processurl(machine, dirs, version):
  if machine.isLinux():
    return "http://www.cmake.org/files/v%(SHORTVERSION)s/cmake-%(VERSION)s.tar.gz" % {"SHORTVERSION" : ".".join(version.split(".")[:2]),  "VERSION":version}
  else:
    return "http://www.cmake.org/files/v%(SHORTVERSION)s/cmake-%(VERSION)s.zip"  % {"SHORTVERSION" : ".".join(version.split(".")[:2]),  "VERSION":version}

URL = processurl
VERSIONS = ["2.8.3", "2.8.4"]
DEFAULT_VERSION = "2.8.4"

from source.builders import ConfigureMakeBuilder
import os

class CMakeBootStrapBuilder( ConfigureMakeBuilder ):
  """ subclass of ConfigureMakeBuilder with custom configure step """

  def getbindir(self):
    return self.targetpath() + "/bin"

  def configure( self ):
     os.chdir( self.extractedpath )
     self.execute("./bootstrap --prefix=" + self.installpath() )

class TodoBuilder( ConfigureMakeBuilder ):
  """ subclass of ConfigureMakeBuilder with custom configure step """

  def getbindir(self):
    return self.targetpath() + "/bin"

  def process(self):
    print "CMake builder not implemented for Windows"

def decider( machine, dirs ):
  return { "Linux" : CMakeBootStrapBuilder, "Windows" : TodoBuilder }[machine.platform]

BUILDER = decider

